import { createApp } from "vue";
import { createPinia } from "pinia";
import router from "./router";
import "./style.css";
import App from "./App.vue";

// Performance monitoring
if (import.meta.env.PROD) {
    // Add performance observer for Core Web Vitals
    if ("PerformanceObserver" in window) {
        const observer = new PerformanceObserver((list) => {
            for (const entry of list.getEntries()) {
                if (entry.entryType === "largest-contentful-paint") {
                    console.log("LCP:", entry.startTime);
                }
                if (entry.entryType === "first-input") {
                    console.log(
                        "FID:",
                        entry.processingStart - entry.startTime
                    );
                }
                if (entry.entryType === "layout-shift") {
                    console.log("CLS:", entry.value);
                }
            }
        });

        observer.observe({
            entryTypes: [
                "largest-contentful-paint",
                "first-input",
                "layout-shift",
            ],
        });
    }
}

// Error handling
window.addEventListener("error", (event) => {
    console.error("Global error:", event.error);
    // In production, you might want to send this to an error tracking service
});

window.addEventListener("unhandledrejection", (event) => {
    console.error("Unhandled promise rejection:", event.reason);
    // In production, you might want to send this to an error tracking service
});

const app = createApp(App);
const pinia = createPinia();

app.use(pinia);
app.use(router);

// Global error handler for Vue
app.config.errorHandler = (err, instance, info) => {
    console.error("Vue error:", err, info);
    // In production, you might want to send this to an error tracking service
};

app.mount("#app");
